package com.res.share.common;

import java.io.Serializable;

public class WebResponse<T> implements Serializable {
    public static final int SUCCESS = 200;
    public static final int ERROR = 500;
    private int status = SUCCESS;
    private String message = "";
    private T rt;

    /**
     * 成功返回
     * @return
     */
    public static WebResponse ok() {
        WebResponse webResponse = new WebResponse();
        webResponse.setStatus(SUCCESS);
        webResponse.setMessage(WebConstants.HTTP_200_SUCCESS);
        return webResponse;
    }

    public static <V> WebResponse<V> ok(V v) {
        WebResponse webResponse = new WebResponse();
        webResponse.setStatus(SUCCESS);
        webResponse.setMessage(WebConstants.HTTP_200_SUCCESS);
        webResponse.setRt(v);
        return webResponse;
    }

    public static <V> WebResponse<V> ok(V v, String message) {
        WebResponse webResponse = new WebResponse();
        webResponse.setStatus(SUCCESS);
        webResponse.setMessage(message);
        webResponse.setRt(v);
        return webResponse;
    }

    /**
     * 返回错误
     * @return
     */
    public static WebResponse error() {
        WebResponse webResponse = new WebResponse();
        webResponse.setRt(ERROR);
        webResponse.setMessage(WebConstants.HTTP_500_ERROR);
        return webResponse;
    }

    public static WebResponse error(int code) {
        WebResponse webResponse = new WebResponse();
        webResponse.setRt(code);
        webResponse.setMessage(WebConstants.HTTP_500_ERROR);
        return webResponse;
    }

    public static WebResponse error(int code, String message) {
        WebResponse webResponse = new WebResponse();
        webResponse.setStatus(code);
        webResponse.setMessage(message);
        return webResponse;
    }

    //<editor-fold defaultstate="collapsed" desc="delombok">
    @SuppressWarnings("all")
    public WebResponse() {
    }

    @SuppressWarnings("all")
    public int getStatus() {
        return this.status;
    }

    @SuppressWarnings("all")
    public String getMessage() {
        return this.message;
    }

    @SuppressWarnings("all")
    public T getRt() {
        return this.rt;
    }

    @SuppressWarnings("all")
    public void setStatus(final int status) {
        this.status = status;
    }

    @SuppressWarnings("all")
    public void setMessage(final String message) {
        this.message = message;
    }

    @SuppressWarnings("all")
    public void setRt(final T rt) {
        this.rt = rt;
    }

    @Override
    @SuppressWarnings("all")
    public boolean equals(final Object o) {
        if (o == this) return true;
        if (!(o instanceof WebResponse)) return false;
        final WebResponse<?> other = (WebResponse<?>) o;
        if (!other.canEqual((Object) this)) return false;
        if (this.getStatus() != other.getStatus()) return false;
        final Object this$message = this.getMessage();
        final Object other$message = other.getMessage();
        if (this$message == null ? other$message != null : !this$message.equals(other$message)) return false;
        final Object this$rt = this.getRt();
        final Object other$rt = other.getRt();
        if (this$rt == null ? other$rt != null : !this$rt.equals(other$rt)) return false;
        return true;
    }

    @SuppressWarnings("all")
    protected boolean canEqual(final Object other) {
        return other instanceof WebResponse;
    }

    @Override
    @SuppressWarnings("all")
    public int hashCode() {
        final int PRIME = 59;
        int result = 1;
        result = result * PRIME + this.getStatus();
        final Object $message = this.getMessage();
        result = result * PRIME + ($message == null ? 43 : $message.hashCode());
        final Object $rt = this.getRt();
        result = result * PRIME + ($rt == null ? 43 : $rt.hashCode());
        return result;
    }

    @Override
    @SuppressWarnings("all")
    public String toString() {
        return "WebResponse(status=" + this.getStatus() + ", message=" + this.getMessage() + ", rt=" + this.getRt() + ")";
    }
}
    //</editor-fold>
